/**
 * Created by sean on 15-7-20.
 */
var isIE = window.ActiveXObject;
var typeToBand = {
    L1CA: 'L1',
    G1CA: 'L1',
    G1P: 'L1',
    E1: 'L1',
    E1BOC: 'L1',
    E1CBOC: 'L1',
    L1: 'L1',
    L1C: 'L1',
    L1CBOC: 'L1',
    L1CTMBOC: 'L1',
    L1E: 'L1',
    L1P: 'L1',
    B1: 'L1',
    L1SAIF: 'L1',
    L2E: 'L2',
    L2P: 'L2',
    L2C: 'L2',
    L2CM: 'L2',
    L2CL: 'L2',
    'L2CM+CL': 'L2',
    G2CA: 'L2',
    G2P: 'L2',
    L5: 'L5',
    L5CA: 'L5',
    L5I: 'L5',
    L5Q: 'L5',
    'L5I+Q': 'L5',
    G3: 'L5',
    G3D: 'L5',
    G3P: 'L5',
    'G3D+P': 'L5',
    E5A: 'L5',
    E5B: 'L5',
    E5Alt: 'L5',
    B2: 'L5',
    E6: 'L6',
    B3: 'L6',
    LEX: 'L6',
    XPS: 'L1'
};
function $id(id) {
    return getDOMElementById(id);
}
function doHelp(file) {
    trmbTop.showHelp(trmbTop.sysData.HelpProtocol + trmbTop.sysData.HelpLink + trmbTop.language + '/' + file + '.html', 'help');
    return false;
}
function translate() {
    var tags = document.getElementsByTagName("trans");
    for (var i = 0; i < tags.length; i++) {
        var text;
        var name = tags[i].getAttribute("name");
        if (parent.getString) {
            text = parent.getString(name);
        } else {
            text = parent.parent.getString(name);
        }
        var txtNode = document.createTextNode(text);
        tags[i].parentNode.insertBefore(txtNode, tags[i]);
    }
}
function createElem() {
    var type = arguments[0];
    var e = document.createElement(type);
    for (var i = 1; i < arguments.length; i = i + 2) {
        e.setAttribute(arguments[i], arguments[i + 1]);
    }
    return e;
}
function discardElement(element) {
    if (element.tagName == "HTML" || element.tagName == "HEAD" || element.tagName == "BODY" || element.id == "IELeakGarbageBin") {
        throw new Error("Do not call discardElement() on entire page");
    }
    var garbageBin = getDOMElementById('IELeakGarbageBin');
    if (!garbageBin) {
        garbageBin = document.createElement('DIV');
        garbageBin.id = 'IELeakGarbageBin';
        garbageBin.style.display = 'none';
        document.body.appendChild(garbageBin);
    }
    garbageBin.appendChild(element);
    garbageBin.innerHTML = '';
}
function ReleaseEvents(elem) {
    var events = ["focus", "blur", "change", "click", "mousedown", "mouseup", "mouseover", "keypress", "keydown", "keyup", "keypress"];
    var helper = function(obj) {
        var i;
        for (i = 0; i < events.length; i++) {
            if (obj["on" + events[i]]) {
                obj["on" + events[i]] = null;
            }
        }
        for (i = 0; i < obj.childNodes.length; i++) {
            helper(obj.childNodes[i]);
        }
    };
    helper(elem);
}
function showBarGraph(id, classname, width, amount, total) {
    var h;
    h = '<table cellspacing="0" height="20" width="' + width + '"><tr>';
    var pixels = width * (amount / total);
    if (pixels < 1) {
        h += '<td/>';
    } else if (classname == 'key') {
        h += '<td class="key" align="left" width="50%">0%</td>' + '<td class="key" align="right" width="50%">100%</td>';
    } else {
        h += '<td class="' + classname + '" width="' + pixels + '"/><td/>';
    }
    h += '</tr></table>';
    getDOMElementById(id).innerHTML = h;
}
function rateNum2Str(rate) {
    var sec = getString('secAbbr');
    var min = getString('MinAbbr');
    switch (rate) {
        case '16':
            return '100Hz';
        case '15':
            return '50Hz';
        case '13':
            return '20Hz';
        case '1':
            return '10Hz';
        case '2':
            return '5Hz';
        case '11':
            return '2Hz';
        case '3':
            return '1Hz';
        case '4':
            return '2 ' + sec;
        case '5':
            return '5 ' + sec;
        case '6':
            return '10 ' + sec;
        case '12':
            return '15 ' + sec;
        case '7':
            return '30 ' + sec;
        case '8':
            return '1 ' + min;
        case '9':
            return '5 ' + min;
        case '10':
            return '10 ' + min;
        default:
            return '?Hz';
    }
}
function sortNumber(a, b) {
    return b - a;
}
function getFastestRateStr(gsofRateArray) {
    var rate = new Array(gsofRateArray.length);
    for (var j = 0; j < gsofRateArray.length; j++) {
        switch (gsofRateArray[j]) {
            case '16':
                rate[j] = 100;
                break;
            case '15':
                rate[j] = 50;
                break;
            case '13':
                rate[j] = 20;
                break;
            case '1':
                rate[j] = 10;
                break;
            case '2':
                rate[j] = 5;
                break;
            case '11':
                rate[j] = 2;
                break;
            case '3':
                rate[j] = 1;
                break;
            case '4':
                rate[j] = -2;
                break;
            case '5':
                rate[j] = -5;
                break;
            case '6':
                rate[j] = -10;
                break;
            case '12':
                rate[j] = -15;
                break;
            case '7':
                rate[j] = -30;
                break;
            case '8':
                rate[j] = -60;
                break;
            case '9':
                rate[j] = -300;
                break;
            case '10':
                rate[j] = -600;
                break;
            default:
                rate[j] = 0;
        }
    }
    rate.sort(sortNumber);
    var sec = getString('secAbbr');
    var min = getString('MinAbbr');
    switch (rate[0]) {
        case 100:
            return '100Hz';
        case 50:
            return '50Hz';
        case 20:
            return '20Hz';
        case 10:
            return '10Hz';
        case 5:
            return '5Hz';
        case 2:
            return '2Hz';
        case 1:
            return '1Hz';
        case - 2 : return '2 ' + sec;
        case - 5 : return '5 ' + sec;
        case - 10 : return '10 ' + sec;
        case - 15 : return '15 ' + sec;
        case - 30 : return '30 ' + sec;
        case - 60 : return '1 ' + min;
        case - 300 : return '5 ' + min;
        case - 600 : return '10 ' + min;
        default:
            return '';
    }
}
function Fix2(n) {
    return ((n < 10) ? "0": "") + n;
}
function appendElem(elem, type, str) {
    var x = document.createElement(type);
    if (str) {
        x.appendChild(document.createTextNode(str));
    }
    elem.appendChild(x);
    return x;
}
function appendText(elem, str) {
    elem.appendChild(document.createTextNode(str));
}
function appendHref(elem, href, str) {
    var x = document.createElement("a");
    x.setAttribute("href", href);
    if (str) {
        x.appendChild(document.createTextNode(str));
    }
    elem.appendChild(x);
    return x;
}
function appendElemWAttr(elem, type, attr, str) {
    var x = document.createElement(type);
    for (var i = 0; i < attr.length; i++) {
        x.setAttribute(attr[i].name, attr[i].value);
    }
    if (str) {
        x.appendChild(document.createTextNode(str));
    }
    elem.appendChild(x);
    return x;
}
function appendRow(elem, type, str) {
    var r = elem.insertRow(elem.rows.length);
    if (type) {
        var d = document.createElement(type);
        if (str) {
            d.appendChild(document.createTextNode(str));
        }
        r.appendChild(d);
    }
    return r;
}
function nodeSortNum(a, b) {
    var a = parseInt(a.firstChild.nodeValue);
    var b = parseInt(b.firstChild.nodeValue);
    if (a > b) return 1;
    if (a < b) return - 1;
    return 0;
}
function showSvTrackList(svTrack) {
    forcePropertyToArray(svTrack, 'sv');
    var allSvs = svTrack.sv;
    var svs = new Array({},
        {});
    var totalSvCount = 0;
    for (var i = 0; i < allSvs.length; ++i) {
        var sv = allSvs[i];
        var sys = sv.__sys;
        var ant = sv.__antenna;
        var prn = sv.__PRN;
        if (sys == 'GLONASS') prn = sv.__ALM;
        if (prn.match(/^\d+$/) != null) prn = parseInt(prn);
        forcePropertyToArray(sv, 'cno');
        var cno = 0;
        for (var j = 0; j < sv.cno.length; ++j) {
            if ((cno = sv.cno[j].__str) != 0) break;
        }
        if (cno == 0) continue;
        if (! (sys in svs[ant])) svs[ant][sys] = new Array();
        svs[ant][sys].push(prn);
        if (ant == 0)++totalSvCount;
    }
    h = new htmlContainer();
    h.write('<table class=' + (miniBrowser ? '"miniTitle">': '"bold_title">') + '<td>' + getString('satTrack') + ':' + totalSvCount + '</td></table>');
    h.write('<table class=' + (miniBrowser ? '"miniContent">': '"ll">'));
    systems = ['GPS', 'GLONASS', 'GALILEO', 'BEIDOU', 'IRNSS', 'SBAS', 'QZSS', 'OMNI', 'XPS', ];
    for (var s = 0; s < systems.length; ++s) {
        sys = systems[s];
        if (sys in svs[0]) {
            var antenna1Count = '';
            if (sys in svs[1]) antenna1Count = ', ' + svs[1][sys].length;
            var systemName = sys;
            if (sys == 'OMNI') systemName = getString('MenuOmnistar', GetRxBrand());
            else if (sys == 'GLONASS') systemName = getString('OptGLONASS');
            else if (sys == 'GALILEO') systemName = getString('OptGalileo');
            else if (sys == 'BEIDOU') systemName = getString('OptBeidou');
            else if (sys == 'CDGPS') systemName = getString('OptCDGPS');
            else if (sys == 'XPS') systemName = 'XPS';
            else if (sys == 'IRNSS') systemName = 'IRNSS';
            if (miniBrowser) h.write('<tr><td>' + systemName + ':</td><td>');
            else h.write('<tr><td><nobr>' + systemName + ' (' + svs[0][sys].length + antenna1Count + '):</nobr></td><td>');
            svs[0][sys].sort(function(a, b) {
                if (a > b) return 1;
                if (a < b) return - 1;
                return 0;
            });
            for (var i = 0; i < svs[0][sys].length; ++i) {
                h.write(((i != 0) ? ', ': '') + svs[0][sys][i]);
            }
            h.write('</td></tr>');
        }
    }
    h.write('</table>');
    return h.contents();
}
function showTime() {
    var timeString = '';
    var timeObj;
    var id;
    if (arguments.length == 1) timeObj = arguments[0];
    else if (arguments.length == 2) {
        id = arguments[0];
        timeObj = arguments[1];
    } else if (arguments.length == 3) {
        id = arguments[0];
        timeObj = xmlToObject(arguments[2]).time;
    }
    var week = timeObj.week;
    var sec = timeObj.sec;
    var status = timeObj.status;
    var leap_event = timeObj.pos_leap_event;
    var gpsstart = new Date("Jan 6,1980 00:00:00 UTC");
    var t;
    if (status != 'UNKNOWN') {
        if (leap_event) sec = sec - 1;
        t = new Date(gpsstart.getTime() + (week * 604800000) + (sec * 1000));
        timeString = t.getUTCFullYear() + '-' + Fix2(t.getUTCMonth() + 1) + '-' + Fix2(t.getUTCDate()) + 'T' + Fix2(t.getUTCHours()) + ':' + Fix2(t.getUTCMinutes()) + ':';
        if (leap_event) {
            timeString += Fix2(t.getUTCSeconds() + 1);
        } else {
            timeString += Fix2(t.getUTCSeconds());
        }
        timeString += 'Z';
        timeString += ' (' + status + ')';
    }
    if (id != undefined) getDOMElementById(id).innerHTML = timeString;
    return timeString;
}
function hideElem() {
    for (var i = 0; i < arguments.length; ++i) {
        var elem = arguments[i];
        if (elem && elem.style.display != "none") {
            elem.style.display = 'none';
            elem.style.position = 'absolute';
        }
    }
}
function showElem(elem) {
    for (var i = 0; i < arguments.length; ++i) {
        var elem = arguments[i];
        if (elem && elem.style.display == "none") {
            elem.style.display = '';
            elem.style.position = '';
        }
    }
}
function showHideElem(show) {
    for (var i = 1; i < arguments.length; ++i) {
        var elem = arguments[i];
        if (show) showElem(elem);
        else hideElem(elem);
    }
}
function hideElemById() {
    for (var i = 0; i < arguments.length; ++i) {
        var elem = getDOMElementById(arguments[i]);
        if (!elem) {
            return;
        }
        hideElem(elem);
    }
}
function showElemById(id) {
    for (var i = 0; i < arguments.length; ++i) {
        var elem = getDOMElementById(arguments[i]);
        if (!elem) {
            return;
        }
        showElem(elem);
    }
}
function showHideElemById(show) {
    for (var i = 1; i < arguments.length; ++i) {
        if (show) showElemById(arguments[i]);
        else hideElemById(arguments[i]);
    }
}
function strcksum(str) {
    var retval = 0;
    for (i = 0; i < str.length; i++) {
        retval += str.charCodeAt(i);
    }
    return retval;
}
function dec2deg(dec) {
    var deg = new Array();
    deg[0] = Math.abs(parseFloat(dec));
    mins = (deg[0] - Math.floor(deg[0])) * 60;
    secs = (mins - Math.floor(mins)) * 60;
    mins = Math.floor(mins);
    secs = (Math.round(secs * 1e5) / 1e5);
    deg[0] = Math.floor(deg[0]) + '\260';
    deg[1] = (mins < 10 ? '\u2007': '') + mins + '\47';
    deg[2] = (secs < 10 ? '\u2007': '') + secs.toFixed(5) + '\42';
    return deg;
}
function latLonToString(degrees, type) {
    var negative = (degrees < 0.0);
    if (negative) degrees = -degrees;
    var dir;
    if (type == 'lat') dir = getString(negative ? 'SouthAbbr': 'NorthAbbr');
    else dir = getString(negative ? 'WestAbbr': 'EastAbbr');
    var DMS = dec2deg(degrees);
    var s = DMS[0] + ' ' + DMS[1] + ' ' + DMS[2] + ' ' + dir;
    return s;
}
function getSvList(label, svs, svs_ant1) {
    var numSvs;
    var hdr;
    var list;
    list = "";
    numSvs = 0;
    for (var j = 0; j < svs.length; j++) {
        numSvs++;
        if (j > 0) {
            list += ", ";
        }
        list += svs[j].firstChild.nodeValue;
    }
    hdr = label + " (" + numSvs;
    if (svs_ant1) {
        hdr += ", " + svs_ant1.length;
    }
    hdr += "): ";
    return {
        cnt: numSvs,
        hdr: hdr,
        list: list
    };
}
function showSvsUsed(svsUsed, label, antenna) {
    var totalCount = 0;
    var gpsList = '';
    var gpsCount = 0;
    var glnList = '';
    var glnCount = 0;
    var galList = '';
    var galCount = 0;
    var cmpList = '';
    var cmpCount = 0;
    var sbasList = '';
    var sbasCount = 0;
    var qzssList = '';
    var qzssCount = 0;
    var xpsList = '';
    var xpsCount = 0;
    var tableTitle;
    var tableContent;
    svsUsed.sort(function(a, b) {
        if (parseInt(a.__str) > parseInt(b.__str)) return 1;
        if (parseInt(a.__str) < parseInt(b.__str)) return - 1;
        return 0;
    });
    if (antenna == undefined) antenna = "0";
    for (var i = 0; i < svsUsed.length; ++i) {
        var sv = svsUsed[i];
        if (sv.__antenna != undefined && sv.__antenna != antenna) continue;
        if (sv.__sys == 0) {++totalCount; ++gpsCount;
            if (gpsList != '') gpsList += ', ';
            gpsList += sv.__str;
        } else if (sv.__sys == 1) {++totalCount; ++sbasCount;
            if (sbasList != '') sbasList += ', ';
            sbasList += sv.__str;
        } else if (sv.__sys == 2) {++totalCount; ++glnCount;
            if (glnList != '') glnList += ', ';
            glnList += sv.__str;
        } else if (sv.__sys == 3) {++totalCount; ++galCount;
            if (galList != '') galList += ', ';
            galList += sv.__str;
        } else if (sv.__sys == 4) {++totalCount; ++qzssCount;
            if (qzssList != '') qzssList += ', ';
            qzssList += sv.__str;
        } else if (sv.__sys == 5) {++totalCount; ++cmpCount;
            if (cmpList != '') cmpList += ', ';
            cmpList += sv.__str;
        } else if (sv.__sys == 7) {++totalCount; ++xpsCount;
            if (xpsList != '') xpsList += ', ';
            xpsList += sv.__str;
        }
    }
    var h = new htmlContainer();
    h.write('<table class=' + (miniBrowser ? '"miniTitle">': '"bold_title">') + '<td>' + label + ':' + totalCount + '</td>' + '</table>');
    h.write('<table ' + (miniBrowser ? 'class="miniContent">': '>'));
    if (gpsCount != 0) h.write('<tr><td>GPS' + ((miniBrowser) ? '': '(' + gpsCount + ')') + ':</td><td>' + gpsList + '</td></tr>');
    if (glnCount != 0) h.write('<tr><td>' + getString('OptGLONASS') + (miniBrowser ? '': ('(' + glnCount + ')')) + ':</td><td>' + glnList + '</td></tr>');
    if (galCount != 0) h.write('<tr><td>' + getString('OptGalileo') + (miniBrowser ? '': ('(' + galCount + ')')) + ':</td><td>' + galList + '</td></tr>');
    if (cmpCount != 0) h.write('<tr><td>' + getString('OptBeidou') + (miniBrowser ? '': ('(' + cmpCount + ')')) + ':</td><td>' + cmpList + '</td></tr>');
    if (qzssCount != 0) h.write('<tr><td>' + getString('OptQzss') + (miniBrowser ? '': ('(' + qzssCount + ')')) + ':</td><td>' + qzssList + '</td></tr>');
    if (sbasCount != 0) h.write('<tr><td>' + 'SBAS' + (miniBrowser ? '': ('(' + sbasCount + ')')) + ':</td><td>' + sbasList + '</td></tr>');
    if (xpsCount != 0) h.write('<tr><td>' + 'XPS' + (miniBrowser ? '': ('(' + xpsCount + ')')) + ':</td><td>' + xpsList + '</td></tr>');
    h.write('</table>');
    if (!miniBrowser) h.write('<br/>');
    return h.contents();
}
function permissionToEdit() {
    var xmlData = xmlToObject(getDoc("xml/dynamic/httpd_data.xml"));
    var mode = xmlData.http.security;
    if (mode == 'Disabled') {
        return true;
    }
    var user = xmlData.http.currentUser;
    if (user == undefined) return false;
    var elem = objWithAttr(xmlData.http.users.elem, 'name', user);
    if (elem == undefined) return false;
    return (elem.allowConfig == "TRUE");
}
function submitIfAllowed(form) {
    if (!permissionToEdit()) {
        alert(getString("NoConfigChangeAllowed"));
        return;
    }
    form.submit();
}
function SetListSelectedValue(list, selectedValue) {
    var i;
    list.selectedIndex = 0;
    for (i = 0; i < list.options.length; i++) {
        if (list.options[i].value == selectedValue) {
            list.selectedIndex = i;
        }
    }
}
function CreateOptColoured(str, val, health) {
    var opt = document.createElement("option");
    opt.appendChild(document.createTextNode(str));
    opt.value = val;
    if (health == false) {
        opt.style.color = "red";
    }
    return opt;
}
function htmlContainer() {
    this.data = "";
    this.open = function() {
        this.data = "";
    };
    this.write = function(data) {
        this.data += data;
    };
    this.close = function() {};
    this.contents = function() {
        return this.data;
    };
    this.writeToInnerHTML = function(id) {
        var el = document.getElementById(id);
        if (el) el.innerHTML = this.data;
    };
    this.row = function() {
        for (var i = 0; i < arguments.length; ++i) this.write('<tr>' + arguments[i] + '</tr>');
    };
    this.cells = function() {
        var s = '';
        for (var i = 0; i < arguments.length; ++i) s += '<td>' + arguments[i] + '</td>';
        return s;
    };
}
function toInnerHtml(id, string) {
    document.getElementById(id).innerHTML = string;
}
function makeRadioButton(cbName, value, currentValue, options) {
    var text;
    text = '<input type="radio" name="' + cbName + '" value="' + value + '" ';
    if (value == currentValue) text += 'checked="on" ';
    if (options != undefined) text += options;
    text += '/>';
    return text;
}
function makeCheckbox(cbName, checked, options) {
    var text;
    text = '<input type="checkbox" name="' + cbName + '" ';
    if (options != undefined) text += options;
    if (checked) text += ' checked="on"';
    text += ' />';
    return text;
}
function makePopupMenu(name, currentValue, selectAttributes) {
    var elements = (makePopupMenu.arguments.length - 3) / 2;
    var popup;
    popup = '<select' + ' name="' + name + '" ' + 'id="' + name + '" ' + selectAttributes + (trmbTop.miniBrowser ? ' class="miniSelection">': '>');
    for (var i = 0; i < elements; ++i) {
        var value = '' + makePopupMenu.arguments[2 * i + 3];
        if (value == '') continue;
        popup += '<option value="' + value + '"' + (value == currentValue ? ' selected="on"': '') + '>' + makePopupMenu.arguments[2 * i + 4] + '</option>';
    }
    popup += '</select>';
    return popup;
}
function makePopupMenuFromArray(name, currentValue, selectAttributes, array) {
    var elements = array.length / 2;
    var popup;
    popup = '<select' + ' name="' + name + '" ' + 'id="' + name + '" ' + selectAttributes + (miniBrowser ? ' class="miniSelection"': '') + '>';
    for (var i = 0; i < elements; ++i) {
        var value = '' + array[2 * i];
        if (value == '') continue;
        popup += '<option value="' + value + '"' + (value == currentValue ? ' selected="on"': '') + '>' + array[2 * i + 1] + '</option>';
    }
    popup += '</select>';
    return popup;
}
function makeButton(name, label, onclick, options) {
    var text;
    text = '<input type="button"' + (name ? ' name="' + name + '" id="' + name + '"': '') + ' value="' + label + '" onclick="' + onclick + '" ' + (miniBrowser ? 'class="miniButton" ': '') + (options != undefined ? options: '') + '/>';
    return text;
}
function cancelButton(url, id) {
    return makeButton((id == undefined) ? 'cancel': id, getString('Cancel'), 'loadDataFrameAfterDelay(\'' + url + '\',0)');
}
function makeTextField(name, value, width, max, options) {
    value = String(value).replace(/&/g, '&amp;').replace(RegExp("'", 'g'), '&#039;').replace(RegExp('"', 'g'), '&quot;').replace(/>/g, '&gt;').replace(/</g, '&lt;');
    var text;
    text = '<input type="text" name="' + name + '" id="' + name + '" value="' + value + '" size="' + width + '" maxlength="' + max + '"' + ((options != undefined) ? options: '') + (miniBrowser ? ' class="miniTextField"': '') + '/>';
    return text;
}
function makePasswordField(name, value, width, max, options) {
    var text;
    text = '<input type="password"' + (miniBrowser ? ' class="miniTextField"': '') + ' name="' + name + '" id="' + name + '" value="' + value + '" size="' + width + '" maxlength="' + max + '" ' + ((options != undefined) ? options: '') + '/>';
    return text;
}
function makeHiddenField(name, value) {
    var text;
    text = '<input type="hidden" name="' + name + '" id="' + name + '" value="' + value + '" />';
    return text;
}
function formToUrl(theForm, url) {
    if (url == '') {
        url = theForm.action;
    }
    var e = theForm.elements;
    var separator = '?';
    for (var i = 0; i < e.length; ++i) {
        if (e[i].type == 'text' || e[i].type == 'hidden' || e[i].type == 'password' || (e[i].type == 'radio' && e[i].checked) || (e[i].type == 'checkbox' && e[i].checked)) {
            url += separator + e[i].name + '=' + encodeURIComponent(e[i].value);
            separator = '&';
        } else if (e[i].type == 'radio' || e[i].type == 'button' || e[i].type == 'checkbox') {} else if (e[i].type == 'select-one') {
            if (e[i].selectedIndex >= 0) {
                p = e[i].options[e[i].selectedIndex].value;
                url += separator + e[i].name + '=' + escape(p);
                separator = '&';
            }
        } else {
            alert('submitForm: problem with ' + e[i].type + '=' + e[i].name);
            return;
        }
    }
    return url;
}
function GetSerialPortName(xmlName) {
    var name;
    if (xmlName == 'Lemo') name = 'Lemo';
    else if (xmlName.substr(0, 4) == 'Lemo') name = 'Lemo ' + xmlName.substr(4);
    else if (xmlName.substr(0, 6) == 'Serial') name = getString("SerialP") + ' ' + xmlName.substr(6);
    else if (xmlName == 'Emulated') name = 'Emulated';
    else name = getString(xmlName);
    return name;
}
function formatISO8601(gpsSeconds) {
    if (gpsSeconds == 0) {
        return '-';
    } else {
        var string = formatISO8601Raw(gpsSeconds);
        string += ' GPS';
        return string;
    }
}
function formatISO8601UTC(gpsSeconds) {
    if (gpsSeconds == 0) {
        return '-';
    } else {
        var string = formatISO8601Raw(gpsSeconds);
        string += 'Z';
        return string;
    }
}
function formatISO8601Raw(gpsSeconds) {
    if (seconds == 0) return '-';
    gpsOffset = 315964800000;
    var dateObject = new Date(gpsSeconds * 1000 + gpsOffset);
    var dayOfMonth = dateObject.getUTCDate();
    dayOfMonth = ((dayOfMonth < 10) ? '0': '') + dayOfMonth;
    var month = dateObject.getUTCMonth() + 1;
    month = ((month < 10) ? '0': '') + month;
    var year = dateObject.getUTCFullYear();
    var hours = dateObject.getUTCHours();
    hours = ((hours < 10) ? '0': '') + hours;
    var minutes = dateObject.getUTCMinutes();
    minutes = ((minutes < 10) ? '0': '') + minutes;
    var seconds = dateObject.getUTCSeconds();
    seconds = ((seconds < 10) ? '0': '') + seconds;
    return '' + year + '-' + month + '-' + dayOfMonth + 'T' + hours + ':' + minutes + ':' + seconds;
}
function isDefined(type) {
    return type != 'undefined' && type != 'unknown';
}
function getDOMElementById(id) {
    if (isDefined(typeof document.getElementById)) {
        return document.getElementById(id);
    } else if (isDefined(typeof document.all)) {
        return document.all[id];
    } else {
        throw new Error("Can not find a method to locate DOM element.");
        return null;
    }
}
function objToTable(obj) {
    var string;
    string = '<table border="1">';
    for (var p in obj) {
        if (typeof(obj[p]) == 'string') {
            string += '<tr><td>' + p + '</td><td>"' + obj[p] + '" &nbsp;&nbsp;(len:' + obj[p].length + ')</td></tr>';
        } else if (typeof(obj[p]) == 'number') {
            string += '<tr><td>' + p + '</td><td>' + obj[p] + ' (number)' + ')</td></tr>';
        } else if (typeof(obj[p]) == 'boolean') {
            string += '<tr><td>' + p + '</td><td>' + obj[p] + ' (boolean)' + ')</td></tr>';
        } else if (obj[p] instanceof Array) {
            string += '<tr><td>' + p + '[len=' + obj[p].length + ']</td><td>&nbsp;</td></tr>';
            for (var i = 0; i < obj[p].length; ++i) {
                string += '<tr><td align="right">' + '[' + i + ']</td>';
                if (typeof(obj[p][i]) == 'string') string += '<td>"' + obj[p][i] + '" &nbsp;&nbsp;(len:' + obj[p][i].length + ')</td></tr>';
                else string += '<td>' + objToTable(obj[p][i]) + '</td></tr>';
            }
        } else if (typeof(obj[p]) == 'object') {
            string += '<tr><td>' + p + '</td><td>' + ((obj[p] === top) ? 'RefToTop': objToTable(obj[p])) + '</td><tr>';
        } else {
            string += '<tr><td>' + p + '</td><td>' + '(' + typeof(obj[p]) + ')' + '</td><tr>';
        }
    }
    string += '</table>';
    return string;
}
function objWithAttr(obj, attrName, attrValue) {
    if (obj == undefined) {} else if (obj instanceof Array) {
        for (var i = 0; i < obj.length; ++i) {
            if (obj[i][attrName] == attrValue) return obj[i];
        }
    } else {
        if (obj[attrName] == attrValue) return obj
    }
    return undefined;
}
function forcePropertyToArray(obj, propName) {
    if (obj[propName] == undefined) obj[propName] = new Array();
    else if (obj[propName] instanceof Array) return;
    else obj[propName] = new Array(obj[propName]);
}
var testStations = new Array("Trimble Sunnyvale, CA, USA", "Trimble Terrasat, HÃ¶henkirchen, Germany", "Trimble Hook, UK", "Trimble Westminster, CO, USA", "Trimble New Zealand, Christchurch", "Trimble Singapore", "Trimble Dayton, OH, USA");
var stations = new Array("PosBeijing", "PosChicago", "PosLondon", "PosMelbourne", "PosMoscow", "PosMunich", "PosNewDelhi", "PosNewYork", "PosParis", "PosPretoria", "PosRio", "PosSF", "PosSantiago", "PosSydney", "PosTokyo");
var AllStationsLLH = [{
    lat: 37.384896686,
    lon: -122.005463678,
    hgt: -6.225
},
    {
        lat: 48.046261778,
        lon: 11.701679711,
        hgt: 623.370
    },
    {
        lat: 51.279596177,
        lon: -0.959547087,
        hgt: 141.945
    },
    {
        lat: 39.898000447,
        lon: -105.112550439,
        hgt: 1663.388
    },
    {
        lat: -43.544877042,
        lon: 172.591424844,
        hgt: 35.633
    },
    {
        lat: 1.302087536,
        lon: 103.90498306,
        hgt: 110.000
    },
    {
        lat: 39.886951587,
        lon: -84.138066234,
        hgt: 263.967
    },
    {
        lat: 39.9,
        lon: 116.391388889,
        hgt: 46.0
    },
    {
        lat: 41.8833,
        lon: -87.63333,
        hgt: 179.0
    },
    {
        lat: 51.5,
        lon: -0.125,
        hgt: 13.0
    },
    {
        lat: -37.813955556,
        lon: 144.966666667,
        hgt: 0.0
    },
    {
        lat: 55.75,
        lon: 37.62,
        hgt: 127.0
    },
    {
        lat: 48.13888889,
        lon: 11.575,
        hgt: 521.0
    },
    {
        lat: 28.6375,
        lon: 77.205555555,
        hgt: 223.0
    },
    {
        lat: 40.71444444,
        lon: -74.0,
        hgt: 5.0
    },
    {
        lat: 48.85,
        lon: 2.35,
        hgt: 43.0
    },
    {
        lat: -25.73333333,
        lon: 28.21666667,
        hgt: 1300.0
    },
    {
        lat: -22.90833333,
        lon: -41.2,
        hgt: 8.0
    },
    {
        lat: 37.778888889,
        lon: -122.418888889,
        hgt: 20.0
    },
    {
        lat: -33.46,
        lon: -70.64,
        hgt: 555.0
    },
    {
        lat: -33.866666667,
        lon: 151.206944444,
        hgt: 45.0
    },
    {
        lat: 35.666666667,
        lon: 139.766666667,
        hgt: 29.0
    }];
function getStationLL(ID) {
    return {
        lat: AllStationsLLH[ID].lat,
        lon: AllStationsLLH[ID].lon
    };
}
function getStationString(PosID) {
    var NumNoTrans = testStations.length;
    if (PosID < NumNoTrans) return testStations[PosID];
    else if (PosID < (stations.length + NumNoTrans)) return getString(stations[PosID - NumNoTrans]);
    else return "Unknown";
}
function createStationOptionList(StationID) {
    var Attr = new Array();
    Attr[0] = new Object();
    Attr[0].name = 'value';
    if (trmbTop.testMode) {
        for (i = 0; i < testStations.length; i++) {
            Attr[0].value = i;
            appendElemWAttr(StationID, "option", Attr, testStations[i]);
        }
    }
    for (i = 0; i < stations.length; i++) {
        Attr[0].value = i + testStations.length;
        appendElemWAttr(StationID, "option", Attr, getString(stations[i]));
    }
}
function okToDiv(divId) {
    toInnerHtml(divId, '<h2>' + getString('OK') + '</h2>');
}